<?php
if(isset($dcommittee)){
    $item_name = strlen($dcommittee['Committee']['item_name'])>2 ? $dcommittee['Committee']['item_name'] : 'Project';
}
?>
<div class="search">
    <h3><?php __('Filters') ?></h3>
    <div class="box">
    <?php echo $this->element('form_instructions', array('notefor'=>'filter')); ?>
<?php 
if ($from == 'meetings/view') {
    echo $form->create('Meeting',array('url'=>array('controller'=>'meetings','action'=>'view','committee'=>$this->params['pass'][0],'id'=>$this->params['id'])));

    echo $form->hidden('Search.meeting_id',array('value'=>$this->params['id']));
    echo $form->hidden('Search.from',array('value'=>$from));
    echo $form->input(
        'Search.item',
        array(
            'type' => 'select',
            'options' => $projects,
            'selected' => (isset($cursearch_project) && $cursearch_project!='')?$cursearch_project:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => ucwords($item_name)
        )
    );
    echo $form->input(
        'Search.group',
        array(
            'type' => 'select',
            'options' => $groups,
            'selected' => (isset($cursearch_group) && $cursearch_group!='')?$cursearch_group:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => __('Group Implementor',true)
        )
    );
    echo $form->input(
        'Search.user',
        array(
            'type' => 'select',
            'options' => $users,
            'selected' => (isset($cursearch_user) && $cursearch_user!='')?$cursearch_user:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => __('Individual Implementor',true)
        )
    );
    //echo $form->button('Submit', array('type'=>'submit'))

} else if ($from == 'items/view') {
    echo $form->create('Item',array('url'=>array('controller'=>'items','action'=>'view','committee'=>$this->params['pass'][0],'id'=>$this->params['id'])));

    echo $form->hidden('Search.item_id',array('value'=>$this->params['id']));
    echo $form->hidden('Search.from',array('value'=>$from));
    echo $form->input(
        'Search.meeting',
        array(
            'type' => 'select',
            'options' => $meetings,
            'selected' => (isset($cursearch_meeting) && $cursearch_meeting!='')?$cursearch_meeting:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => __('Meeting Num',true)
        )
    );
    echo $form->input(
        'Search.group',
        array(
            'type' => 'select',
            'options' => $groups,
            'selected' => (isset($cursearch_group) && $cursearch_group!='')?$cursearch_group:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => __('Group Implementor',true)
        )
    );
    echo $form->input(
        'Search.user',
        array(
            'type' => 'select',
            'options' => $users,
            'selected' => (isset($cursearch_user) && $cursearch_user!='')?$cursearch_user:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()',
            'label' => __('Individual Implementor',true)
        )
    );

} else if ($from == 'users/index') { 
    echo $form->create('Users',array('url'=>array('controller'=>'users','action'=>'index')));

    echo $form->input('Search.username', array('value'=>$session->read('Search.username'),'label'=>__('Username',true)));
    echo $form->input('Search.name', array('value'=>$session->read('Search.name')));
    echo $form->input('Search.job_title', array('value'=>$session->read('Search.job_title'),'label'=>__('Post',true)));
    echo $form->input('Search.email', array('value'=>$session->read('Search.email')));
    echo $form->input(
        'Search.committee',
        array(
            'type' => 'select',
            'options' => $committee,
            'selected' => $session->check('Search.committee') ? $session->read('Search.committee'):null,
            'empty' =>  __('--please select--',true)
        )
    );
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'memberships/index') { 
    echo $form->create('Membership',array('url'=>array('controller'=>'memberships','action'=>'index','committee'=>$dcommittee['Committee']['short_name'])));
    echo $form->input('Search.name', array('value'=>$cursearch_name));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'titles/index') { 
    echo $form->create('Title',array('url'=>array('controller'=>'titles','action'=>'index')));
    echo $form->input('Search.short', array('value'=>$session->read('Search.short'),'label'=>__('Title',true)));
    //echo $form->input(__('Search.long',true), array('value'=>$session->read('Search.long')));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'roles/index') { 
    echo $form->create('Role',array('url'=>array('controller'=>'roles','action'=>'index')));
    echo $form->input('Search.name', array('value'=>$session->read('Search.name')));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'systemtodos/index' || $from == 'committeetodos/index') { 
    if ($from == 'committeetodos/index')  $url = array('controller'=>'committeetodos','action'=>'index','committee'=>$dcommittee['Committee']['short_name']);
    if ($from == 'systemtodos/index')  $url = array('controller'=>'systemtodos','action'=>'index');

    echo $form->create('Todo',array('url'=>$url));
    echo $form->input('Search.name', array('value'=>$session->read('Search.name')));
    echo $form->input(
        'Search.priority',
        array(
            'type' => 'select',
            'options' => $priorities,
            'selected' => $session->check('Search.priority') ? $session->read('Search.priority'):null,
            'empty' =>  __('--please select--',true)
        )
    );
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'Templates/index' || $from == 'templates/index') { 
    if ($from == 'Templates/index')  $url = array('controller'=>'Templates','action'=>'index','committee'=>$dcommittee['Committee']['short_name']);
    else $url = array('controller'=>'templates','action'=>'index');

    echo $form->create('Template',array('url'=>$url));
    echo $form->input('Search.title', array('value'=>$session->read('Search.title'),'label'=>__('Message title',true)));
    echo $form->input('Search.description', array('value'=>$session->read('Search.description'),'size'=>'40'));
    echo $form->input('Search.message', array('value'=>$session->read('Search.message'),'size'=>'40','label'=>__('Message',true)));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'groups/index') { 
    echo $form->create('Group',array('url'=>array('controller'=>'groups','action'=>'index','committee'=>$dcommittee['Committee']['short_name'])));
    echo $form->input('Search.name', array('value'=>$session->read('Search.name')));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'logs/index') { 
    echo $form->create('Log',array('type'=>'GET','url'=>array('controller'=>'logs','action'=>'index')));
    echo $form->input('Search.user', array('value'=>$session->read('Search.name')));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'logs/report') { 
    echo $form->create('Log',array('url'=>array('controller'=>'logs','action'=>'report')));
    echo $form->input(
        'Search.report',
        array(
            'type' => 'select',
            'options' => $reporttype,
            'selected' => $session->check('Search.report') ? $session->read('Search.report'):null,
            'empty' =>  __('--please select--',true)
        )
    );
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} else if ($from == 'committees/find') { 
    echo $form->create('Committee',array('url'=>array('action'=>'find','controller'=>'committees')));
    __('This will search the keyword in Decisions, Meetings, Filenames, Items/Projects and Status.');
    echo $form->input('Search.text', array('value'=>$dtext[0],'size'=>'40','label'=>__('Keyword',true)));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'parent.location="'.Router::url('/').'"')));

} elseif($from == 'items/index') { 
    echo $form->create('Item',array('url'=>array('controller'=>'items','action'=>'index','committee'=>$dcommittee['Committee']['short_name'])));
    echo $form->input('Search.name', array('value'=>$cursearch_name));
    echo $form->input('Search.short_name', array('value'=>$cursearch_shortname));
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')).'&nbsp;'.$form->button(__('Cancel', true), array('type'=>'button', 'onclick'=>'history.go(-1)')));

} elseif($from== 'wfmodels/index'){
    echo $form->create('Wfmodel',array('url'=>array('controller'=>'wfmodels','action'=>'index','committee'=>$this->params['pass'][0])));
    echo $form->input(
        'Search.role',
        array(
            'type' => 'select',
            'options' => $roles,
            'selected' => (isset($cursearch_role) && $cursearch_role!='')?$cursearch_role:null,
            'empty' =>  __('--please select--',true),
            'onChange'=>'javascript:form.submit()'
        )
    );
    
} elseif($from == 'committees/search'){
    echo $form->create('Committee',array('url'=>array('controller'=>'committees',
                'action'=>'search',
                'committee'=>$dcommittee['Committee']['short_name'])));
    echo $form->input(
        'Search.status',
        array(
            'type' => 'select',
            'options' => array('takenontime'=>__('Taken, on time',true),
                                 'takenlate'=>__('Taken, late',true),
                                 'nottaken'=>__('Not taken, before due date',true),
                                 'nottakenlate'=>__('Not taken, overdue',true)),
            'selected' => (isset($cursearch) && $cursearch!='')?$cursearch:null,
            'empty' =>  __('--please select--',true),
            'label' => __('Action Status',true)
        )
    );
    echo $form->input(
        'Search.meeting',
        array(
            'type' => 'select',
            'options' => $meetings,
            'selected' => (isset($cursearch1) && $cursearch1!='')?$cursearch1:null,
            'empty' =>  __('--please select--',true)
        )
    );
    echo $form->input(
        'Search.chairperson',
        array(
            'type' => 'select',
            'options' => $chairpersons,
            'selected' => (isset($cursearch0) && $cursearch0!='')?$cursearch0:null,
            'empty' =>  __('--please select--',true)
        )
    );
    $dates = $datePicker->picker('Search.from', array('dateFormat'=>'Y-m-d','label'=>__('from',true),'inline'=>true)).
                $datePicker->picker('Search.to', array('dateFormat'=>'Y-m-d','label'=>__('to',true),'inline'=>true));
    echo $html->div('date',$form->label(__('Date range ( Action Deadline)',true)).$dates);
    echo $form->input('Search.keyword');
    echo $html->div('',$form->button(__('Search!', true), array('type'=>'submit')));
}

?>  
    <?php echo $form->end();?>
    </div>
</div>
<p></p>
<?php 
// meeting/view, items/view have no pagination -> so no $paginator
if ($from != 'meetings/view' && $from != 'items/view' && $from != 'logs/report' && $from != 'committees/find' && $from != 'memberships/index' && $from != 'wfmodels/index' && $from != 'committees/search') 
    echo $html->div('num_of_records',__('No. of records:',true).' '.$paginator->counter(array('format'=>'%count%'))); 
?>
